home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / recent / http_t.lha / HTTP.thor next >
Text File  |  1998-06-19  |  9KB  |  322 lines

  1. /*
  2.    $VER http.thor 0.9 (16.6.98)
  3.    Up to V0.8 by Remco van Hooff
  4.    V0.9 by John S. Burger (jsburger@xmission.com)
  5.  
  6. !~ "HISTORY"
  7.    0.2 - URL is now shown in the Browser/GetNET requester (only if he parsed
  8.          URL doesn't contain a doublequote).
  9.        - Added Index to locate the presence of the arexx port
  10.          of a browser.
  11.        - Added SCREENTOFRONT and RELOAD for AWeb.
  12.        - Removed loading of rexxsupport.library, it's not needed.
  13.        - Forgot to call the Thor ARexx port before calling REQUESTNOTIFY.
  14.  
  15.    0.3 - Fixed the non working AMosaic part.
  16.        - Added Voyager support.
  17.        - Start browser when needed.
  18.        - Start TCP/IP stack when needed (optionally, AWebII 2.1+ only).
  19.        - Optionally save the url (IBrowse 1.02+ only).
  20.        - Distributed on IRC only.
  21.  
  22.    0.4 - Changed the way the auto url save thingy for IBrowse works.
  23.          It now waits until the title isn't '(Untitled)' or after the
  24.          timeout period has passed.
  25.          Thanks to Shaun Downend for helping to fix this.
  26.  
  27.    0.5 - Forgot to start the TCP/IP stack if a browser wasn't running yet.
  28.        - Changed the requester text when a browser would fain to start.
  29.        - Now Checking for a browser presence before the first requester
  30.          pops up, saving one requester when the browser isn't found.
  31.        - Will ask what to do when the page title returned is 'IBrowse Error',
  32.          'Proxy Message' or '(Untitled)'. (IBrowse only)
  33.  
  34.    0.6 - Added Retry button to the requester that pops up if IBrowse is unable
  35.          grab the page title within the timeout. Retry will grab the current
  36.          tilte and save the url with that title (much like the add button in
  37.          IBrowse itself).
  38.  
  39.    0.7 - Added external config handling stuff.
  40.        - Changed the Voyager ARexx port from MINDWALKER to VOYAGER. This change
  41.          means that only Voyager 2.0+ will be supported
  42.  
  43.    0.8 - Removed old config things.
  44.        - Added option to start cfgHTTP when no config is found.
  45.        - Removed ~ in the check_tcp.
  46.  
  47.    0.9 - Fixed a problem with certain URL's that were not passed correctly
  48.          to the browsers. The URL's are now passed to the browser in double
  49.          quotes. This has only been tested with Ibrowse.
  50.  
  51.  
  52. ~!
  53. */
  54.  
  55. /*!~ "Variables" */
  56. cfgpath = 'env:thor/'
  57. cfgfile = 'http.config'
  58. CALL OPEN(tmp, 'env:thor/thorpath')
  59.   thorpath = readln(tmp)
  60. CALL CLOSE(tmp)
  61. /*~!*/
  62.  
  63. /*!~ "Init" */
  64. OPTIONS RESULTS
  65. OPTIONS FAILAT 31
  66. /*TRACE RESULTS*/
  67.  
  68. p=' '||ADDRESS()||' '||SHOW('P',,)
  69. IF POS(' THOR.',p)>0 THEN thorport=WORD(SUBSTR(p,POS(' THOR.',p)+1),1)
  70. ELSE DO
  71.   SAY 'THOR port not found!'
  72.   EXIT 10
  73. END
  74.  
  75. IF ~SHOW('p', 'BBSREAD') THEN DO
  76.   ADDRESS COMMAND
  77.     "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  78.     "WaitForPort BBSREAD"
  79. END
  80.  
  81. IF ~SHOW('L','rexxsupport.library') THEN CALL ADDLIB('rexxsupport.library',0,-30,0)
  82. IF ~SHOW('L','rexxsupport.library') THEN DO
  83.   'REQUESTNOTIFY TEXT "Couldn''t open rexxsupport.library" BT "_Ok"'
  84.   EXIT
  85. END
  86. /*~!*/
  87.  
  88. /*!~ "Main"*/
  89. PARSE ARG url
  90.  
  91. CALL loadprefs
  92. ADDRESS(thorport)
  93. CALL check_browser
  94.  
  95. reqtxt = url'\n\nWhat do you want to do with the URL?\n · Send URL to WWW Browser\n · Save the URL using GetNET'
  96. IF browser_port THEN buttons = '_Browser|_GetNET|_Quit'
  97. ELSE buttons = '_Start Browser|_GetNET|_Quit'
  98.  
  99. 'REQUESTNOTIFY TEXT "'reqtxt'" BT "'buttons'"'
  100. answer = RESULT
  101.  
  102. IF browser_port THEN DO
  103.   SELECT
  104.     WHEN answer = 1 THEN DO
  105.       CALL check_tcp
  106.       CALL send_browser
  107.     END
  108.     WHEN answer = 2 THEN CALL send_getnet
  109.     OTHERWISE EXIT
  110.   END
  111. END
  112.  
  113. ELSE DO
  114.   SELECT
  115.     WHEN answer = 1 THEN DO
  116.       CALL check_tcp
  117.       CALL start_browser
  118.     END
  119.     WHEN answer = 2 THEN CALL send_getnet
  120.     OTHERWISE EXIT
  121.   END
  122. END
  123.  
  124. EXIT
  125. /*~!*/
  126.  
  127. /*!~ "LoadPrefs" */
  128. loadprefs:
  129.   IF ~EXISTS(cfgpath||cfgfile) THEN DO
  130.     Address(thorport)
  131.     'Requestnotify TEXT "Could not find the configuration file.\nRun CfgHTTP to create one or quit." BT "_CfgHTTP|_Quit"'
  132.     IF RC = 0 THEN DO
  133.       IF RESULT = 0 THEN EXIT
  134.       IF RESULT = 1 THEN ADDRESS COMMAND 'rx' thorpath'rexx/cfghttp.thor'
  135.     END
  136.     EXIT
  137.   END
  138.   ELSE DO
  139.     CALL OPEN(prf,cfgpath||cfgfile,'R')
  140.       DO UNTIL EOF(prf)
  141.         line = READLN(prf)
  142.         SELECT
  143.           WHEN UPPER(WORD(line,1)) = 'GETNET' THEN DO
  144.             getnet = SUBWORD(line,2)
  145.           END
  146.           WHEN UPPER(WORD(line,1)) = 'BROWSER' THEN DO
  147.             browser = WORD(line,2)
  148.           END
  149.           WHEN UPPER(WORD(line,1)) = 'BROWSEREXE' THEN DO
  150.             browserexe = SUBWORD(line,2)
  151.           END
  152.           WHEN UPPER(WORD(line,1)) = 'SAVE_URL' THEN DO
  153.             save_url = WORD(line,2)
  154.           END
  155.           WHEN UPPER(WORD(line,1)) = 'SAVEDELAY' THEN DO
  156.             savedelay = WORD(line,2)
  157.           END
  158.           WHEN UPPER(WORD(line,1)) = 'AWEB_TCP' THEN DO
  159.             aweb_tcp = WORD(line,2)
  160.           END
  161.           WHEN UPPER(WORD(line,1)) = 'TCP_IP' THEN DO
  162.             tcp_ip = SUBWORD(line,2)
  163.           END
  164.           OTHERWISE NOP
  165.         END
  166.       END
  167.     CALL CLOSE(prf)
  168.     CALL checkprefs
  169.   END
  170. RETURN
  171. /*~!*/
  172.  
  173. /*!~ "CheckPrefs" */
  174. checkprefs:
  175.   IF getnet = ''                 THEN CALL prefserror('GETNET')
  176.   IF ~DATATYPE(browser, 'NUM')   THEN CALL prefserror('BROWSER')
  177.   IF browserexe = ''             THEN CALL prefserror('BROWSEREXE')
  178.   IF ~DATATYPE(save_url, 'BIN')  THEN CALL prefserror('SAVE_URL')
  179.   IF ~DATATYPE(savedelay, 'NUM') THEN CALL prefserror('SAVEDELAY')
  180.   IF ~DATATYPE(aweb_tcp, 'BIN')  THEN CALL prefserror('AWEB_TCP')
  181.   IF tcp_ip = '' THEN tcp_ip = 'RequestChoice >NIL: TITLE="HTTP ERROR" BODY="No TCP/IP stack to run. Use CfgHTTP to edit." GADGETS="OK" Pubscreen=Thor.1'
  182. RETURN
  183. /*~!*/
  184.  
  185. /*!~ "PrefsError" */
  186. prefserror:
  187.   prferr = ARG(1)
  188.   ADDRESS(thorport)
  189.   'REQUESTNOTIFY TEXT "The config file is not in the\ncorrect format. An error occured at\nor before 'prferr'.\nPlease run CfgHTTP to correct this.\n\nIf the problem remains, contact\nthe author at rvhooff@caiw.nl" BT "_OK"'
  190.   EXIT
  191. RETURN
  192. /*~!*/
  193.  
  194. /*!~ "Check for Browser" */
  195. check_browser:
  196.   SELECT
  197.     WHEN INDEX(SHOW('P'),'IBROWSE') > 0 THEN DO
  198.       browser_port = 1
  199.       RETURN
  200.     END
  201.     WHEN INDEX(SHOW('P'),'AWEB.1') > 0 THEN DO
  202.       browser_port = 1
  203.       RETURN
  204.     END
  205.     WHEN INDEX(SHOW('P'),'AMOSAIC.1') > 0 THEN DO
  206.       browser_port = 1
  207.       RETURN
  208.     END
  209.     WHEN INDEX(SHOW('P'),'VOYAGER') > 0 THEN DO
  210.       browser_port = 1
  211.       RETURN
  212.     END
  213.     OTHERWISE browser_port = 0
  214.   END
  215. RETURN
  216. /*~!*/
  217.  
  218. /*!~ "Check for TCP/IP"*/
  219. check_tcp:
  220.   IF (aweb_tcp & browser = 2) THEN RETURN
  221.   ELSE DO
  222.     IF ~SHOWLIST('L','bsdsocket.library') THEN DO
  223.       ADDRESS COMMAND tcp_ip
  224.       IF SHOWLIST('L','bsdsocket.library') THEN CALL send_browser
  225.       ELSE DO
  226.         'REQUESTNOTIFY TEXT "No TCP/IP stack found.n\nCan''t connect to the URL." BT "_OK"'
  227.       END
  228.     END
  229.   END
  230. RETURN
  231. /*~!*/
  232.  
  233. /*!~ "Send to Browser" */
  234. send_browser:
  235.   SELECT
  236.     WHEN INDEX(SHOW('P'),'IBROWSE') > 0 THEN DO
  237.       ADDRESS 'IBROWSE'
  238.       'QUERY TITLE'
  239.       oldpagetitle = RESULT
  240.       'GOTOURL' "'url'"'
  241.       IF save_url THEN DO
  242.         timeout = TIME('S')
  243.         DO FOREVER
  244.           'QUERY TITLE'
  245.           pagetitle = RESULT
  246.           IF (pagetitle ~= '(Untitled)' & oldpagetitle ~= pagetitle) THEN LEAVE
  247.           IF TIME('S') >= timeout + savedelay THEN LEAVE
  248.         END
  249.         IF (pagetitle = 'IBrowse Error' | pagetitle = 'Proxy Message' | pagetitle = '(Untitled)') THEN DO
  250.           ADDRESS(thorport)
  251.           'THORTOFRONT'
  252.           reqbody = 'Unable to find the page title for:\n\n'url'\n\nYou have 4 options:\n · Change the title\n · Retry (grab the title now)\n · Clear it (save but no title)\n · Discard the URL and not save it'
  253.           'REQUESTSTRING TITLE "Title error" BODY "'reqbody'" BT "_OK|_Retry|_Clear|_Discard" ID "'pagetitle'"'
  254.           IF (RC = 30) THEN DO
  255.             'REQUESTNOTIFY TEXT "'THOR.LASTERROR'" BT "_Ok"'
  256.             EXIT
  257.           END
  258.           IF RC = 5 THEN EXIT
  259.           IF RC = 0 THEN DO
  260.             IF THORRC = 1 THEN pagetitle = RESULT
  261.             IF THORRC = 2 THEN DO
  262.                ADDRESS 'IBROWSE'
  263.                'QUERY TITLE'
  264.                pagetitle = RESULT
  265.             END
  266.             IF THORRC = 3 THEN pagetitle = ''
  267.           END
  268.         ADDRESS 'IBROWSE'
  269.         END
  270.         'ADDHOTLIST TITLE "'pagetitle'" LOCATION' url
  271.       END
  272.       EXIT
  273.     END
  274.     WHEN INDEX(SHOW('P'),'AWEB.1') > 0 THEN DO
  275.       ADDRESS 'AWEB.1'
  276.       'OPEN URL' "'url'"' 'RELOAD'
  277.       'SCREENTOFRONT'
  278.       EXIT
  279.     END
  280.     WHEN INDEX(SHOW('P'),'AMOSAIC.1') > 0 THEN DO
  281.       ADDRESS 'AMOSAIC.1'
  282.       'JUMP URL' "'url'"'
  283.       EXIT
  284.     END
  285.     WHEN INDEX(SHOW('P'),'VOYAGER') > 0 THEN DO
  286.       ADDRESS 'VOYAGER'
  287.       'OPENURL URL' "'url'"'
  288.       EXIT
  289.     END
  290.     OTHERWISE DO
  291.       'REQUESTNOTIFY TEXT "Browser not found, either your path\nto the browser is incorrect or there\nis another reason your browser is\nunable to start." BT "_OK"'
  292.       EXIT
  293.     END
  294.   END
  295. RETURN
  296. /*~!*/
  297.  
  298. /*!~ "Start Browser"*/
  299. start_browser:
  300.   ADDRESS COMMAND 'run >nil:' browserexe
  301.   SELECT
  302.     WHEN browser = 1 THEN port = 'IBROWSE'
  303.     WHEN browser = 2 THEN port = 'AWEB.1'
  304.     WHEN browser = 3 THEN port = 'AMOSAIC.1'
  305.     WHEN browser = 4 THEN port = 'MINDWALKER'
  306.     OTHERWISE DO
  307.       'REQUESTNOTIFY TEXT "No running browser found." BT "_OK"'
  308.       EXIT
  309.     END
  310.   END
  311.   ADDRESS COMMAND 'waitforport' port
  312.   CALL send_browser
  313. RETURN
  314. /*~!*/
  315.  
  316. /*!~ "Send to GetNET" */
  317. send_getnet:
  318.   ADDRESS COMMAND 'rx' getnet 'URL' url
  319. RETURN
  320. /*~!*/
  321.  
  322.